<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>Booking Sample Home Page</TITLE>
</HEAD>
<BODY>
	<H2>Welcome to the Booking Sample Home Page</H2>
	Time is now: <b><%= new java.util.Date().toString() %></b>
	<table>
	<thead><tr><th>List of Booking</th></tr></thead>
	<tbody><tr><th></th></tr></tbody>
	<tfoot><tr>Total Room: 0</tr></tfoot>
	</table>
	<input value="List Available" type="button" onClick='listAvail()' />
	<input value="List Booked" type="button" onClick='listBooked()' />
	<HR />
	<form >		
	    <H3>Reserve Room in</H3>	    
	    Room Id:<input id="txtRoomId" type="text" size='50' value='Pangkor' /><br />			
	    Booking Id:<input id="txtBookingId" type="text" size='50' value='st001' /><br />	    
	    Booking By:<input id="txtBookingBy" type="text" size='50' value='sam_tan' /><br />
	    Start Time:<input id="txtStartAt" type="text" size='50' value='2013-07-18' /><br />
	    End Time:<input id="txtEndAt" type="text" size='50' value='2013-07-18' /><br />
		<input id="btnReserve" value="Reserve Room" type="button" onClick='Reserve()' />
	</form>
	<HR />
	Unreserve Booking Id:<input id="txtUnBookingId" type="text" size='50' value='st001' />
	<br />			
	<br />
	<input id="btnUnreserve" value="Unreserve Room" type="button" onClick='Unreserve()' />
	<br />			
<script>
	var listAvail = function() {	
		var url = '../rest/booking/rooms/available';
		var successFunc = function(resp, status) {
			if(!resp){
				alert('Undefined Response From URL:'+url);
			}
			$('#response').val(resp.responseText);
		};
		var data = {};
		getjax(url, data, successFunc);
	};

	var listBooked = function() {	
		var url = '../rest/booking/rooms/booked';
		var successFunc = function(resp, status) {
			if(!resp){
				alert('Undefined Response From URL:'+url);
			}
			$('#response').val(resp.responseText);
		};
		var data = {};
		getjax(url, data, successFunc);
	};
	
	var Unreserve = function() {	
		var bookingId=$('#txtUnBookingId').val();
		var url = '../rest/booking/rooms/'+bookingId;
		var successFunc = function(resp, status) {
			if(!resp){
				alert('Undefined Response From URL:'+url);
			}
			$('#response').val(resp.responseText);
		};
		var data = {};
		deljax(url, data, successFunc);
	};
	
	var Reserve = function() {	
		var url = '../rest/booking/rooms';
		var roomId=$('#txtRoomId').val();
		var bookingId=$('#txtBookingId').val();
		var bookingBy=$('#txtBookingBy').val();
		var startAt=$('#txtStartAt').val();
		var endAt=$('#txtEndAt').val();
		var successFunc = function(resp, status) {
			if(!resp){
				alert('Undefined Response From URL:'+url);
			}
			$('#response').val(resp.responseText);
		};
		var data = {
			roomId: roomId,
			bookingId: bookingId,
			bookingBy: bookingBy,
			startAt: startAt,
			endAt: endAt
		};
		posjax(url, data, successFunc);
	};

	
</script>
	<script type="text/javascript" charset="utf-8" src="../lib/jquery.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="../lib/mi-jqcomps.js"></script>
</BODY>
</HTML>
